/*
 * @Author: 葛文杰
 * @Date: 2021/2/2 13:50
 * @Description: egg controller 报表信息
 */

const BaseController = require('./base');

class ReportInfoController extends BaseController {

    /**
     * 获取报表列表
     */
    async getReportList() {
        const { ctx, service } = this;
        const { reportName, pageNo, pageSize } = ctx.request.body;
        let tableData = await service.reportInfo.getReportList(reportName, parseInt(pageNo), parseInt(pageSize));
        this.success({ data: tableData });
    }

    /**
     * 获取报表信息
     * @return {Promise<void>}
     */
    async getReportInfo() {
        const { service } = this;
        let reportInfo = await service.reportInfo.getReportInfo();
        this.success({ data: reportInfo });
    }

    /**
     * 插入报表信息
     * @return {Promise<void>}
     */
    async insertReportInfo() {
        const { ctx, service } = this;
        const { reportName } = ctx.request.body;
        let result = await service.reportInfo.insertReportInfo(reportName);
        if (result) {
            this.success({ data: result });
        } else {
            this.success({ data: result, message: '已存在相同名称报表!' });
        }
    }

    /**
     * 更新报表信息
     * @return {Promise<void>}
     */
    async updateReportInfo() {
        const { service } = this;
        let result = await service.reportInfo.updateReportInfo();
        this.success({ data: result });
    }

    /**
     * 逻辑删除报表信息通过Id
     * @return {Promise<void>}
     */
    async deleteReportInfoById() {
        const { ctx, service } = this;
        let { reportInfoId } = ctx.request.body;
        let result = await service.reportInfo.deleteReportInfoById(reportInfoId);
        this.success({ data: result });
    }
}

module.exports = ReportInfoController;
